const SystemConfigModel = require('../../model/system_config_model.js');
const BaseAdminService = require('./base_admin_service.js');

class SettingMgrService extends BaseAdminService {

    // 列表
    async get_setting() {
        let where = {};
        let orderBy = { 'ID': 'desc' };
        let data = await SystemConfigModel.getAll(where, '*', orderBy, 100, false);
        return data;
    }

    // 保存
    async save_setting(list) {
        if (!list || list.length == 0) {
            this.AppError('数据异常');
        }
        // 更新
        let res = null;
        for (let i = 0; i < list.length; i++) {
            let item = list[i];
            if (item._id) {
                await SystemConfigModel.edit({ '_id': item._id }, { 'value': item.value }, false);
            }
        };
        return {
            res: true
        };
    }

}

module.exports = SettingMgrService;